using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data;
using Crosland.Framework.DataHelper;
using Crosland.Framework.Base;
using Crosland.Offline.Core;
using Crosland.Offline.Data.Helper;

namespace Crosland.Offline.Data.Dao
{
    public class MaterialDao : DaoBase
    {
        public MaterialDao(string strConn) : base(strConn)
        {
        }

        MaterialHelper helper = new MaterialHelper();

        public List<Material> GetByCriteria(string matnr, string maktx, string lgort, string marca, string modelo)
        {
            List<Material> entitys = new List<Material>();
            DbCommand command = dbProvider.GetStoredProcCommand("USP_BUSQUEDA_MATERIALES");
            dbProvider.AddInParameter(command, helper.Matnr, DbType.String, matnr);
            dbProvider.AddInParameter(command, helper.Maktx, DbType.String, maktx);
            dbProvider.AddInParameter(command, helper.Lgort, DbType.String, lgort);
            dbProvider.AddInParameter(command, helper.Marca, DbType.String, marca);
            dbProvider.AddInParameter(command, helper.Modelo, DbType.String, modelo);

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    entitys.Add(helper.Create(dr));
                }
            }

            return entitys;
        }
    }
}
